<template>
	<view class="com-content">
		<block v-for="(obj,index) in list" :key="index">
			<!--聊天-->
			<view class="com-box" @click="tomsg(obj.id,obj.name,type)">
				<!--群聊-->
				<template v-if="type==='group'">
					<view class="com-box-img">
						<view class="com-imgs">
							<block v-for="(item,ind) in obj.head" :key="ind">
								<image class="com-img" :src="item" v-if="ind<9"></image>
							</block>
						</view>
						<view class="number" v-if="obj.num>0 && obj.num < 100">{{obj.num}}</view>
						<view class="number2" v-else-if="obj.num >= 100">99+</view>
					</view>
					<view class="com-box-r">
						<view class="top">
							<view class="name">{{obj.name}}</view>
							<view class="time">{{obj.time}}</view>
						</view>
						<view class="txt">{{obj.msg_name}}：{{obj.msg}}</view>
					</view>
				</template>
				<!--单聊-->
				<template v-else-if="type==='single'">
					<view class="com-imgs">
						<block v-for="(item,i) in obj.head" :key="i">
							<image class="com-img2" :src="item" v-if="i<1"></image>
						</block>
						<view class="number" v-if="obj.num>0 && obj.num < 100">{{obj.num}}</view>
						<view class="number2" v-else-if="obj.num >= 100">99+</view>
					</view>
					<view class="com-box-r">
						<view class="top">
							<view class="name">{{obj.name}}</view>
							<view class="time">{{obj.time}}</view>
						</view>
						<view class="txt">{{obj.msg}}</view>
					</view>
				</template>
			</view>

		</block>
	</view>
</template>

<script>
	export default {
		name: "com-top",
		components: {},
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			},
			type: {
				type: String,
				default: 'group'
			}
		},
		data() {
			return {
				
			}
		},
		methods: {
			tomsg(id,name,type) {
				this.$emit('tomsg',id,name,type)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.com-box {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 20rpx 0;

		.com-box-img {
			width: 96rpx;
			height: 96rpx;
			margin-right: 20rpx;
			position: relative;

			.com-imgs {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-wrap: wrap;
				width: 96rpx;
				height: 96rpx;
				border-radius: 10rpx;
				overflow: hidden;
				padding: 2rpx;
				background: $uni-but-bg-color-b;

				.com-img {
					width: 28rpx;
					height: 28rpx;
					margin: 0 4rpx 4rpx 0;
				}

				.com-img:nth-of-type(3n) {
					margin: 0 0 4rpx 0;
				}
			}

			.number {
				width: 32rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}

			.number2 {
				width: 52rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}
		}

		.com-imgs {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-wrap: wrap;
			width: 96rpx;
			height: 96rpx;
			margin-right: 20rpx;
			border-radius: 10rpx;
			padding: 2rpx;
			background: $uni-but-bg-color-b;
			position: relative;

			.com-img2 {
				width: 96rpx;
				height: 96rpx;
				border-radius: 10rpx;
			}

			.number {
				width: 32rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}

			.number2 {
				width: 52rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}
		}

		.com-box-r {
			width: calc(100% - 116rpx);

			.top {
				display: flex;
				justify-content: space-between;

				.name {
					font-size: 32rpx;
					font-weight: 400;
					color: $font-color-3;
					margin-bottom: 10rpx;
				}

				.time {
					font-size: 24rpx;
					font-weight: 400;
					color: $font-color-b;
				}
			}

			.txt {
				width: calc(100% - 40rpx);
				font-size: 28rpx;
				font-weight: 400;
				color: $font-color-9;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap
			}
		}

	}
</style>
